package com.examplemartin.jpademo.pojo.po.purchase;

import com.examplemartin.jpademo.annotation.EntityCheck;
import com.examplemartin.jpademo.pojo.admin.BaseEntity;
import com.examplemartin.jpademo.pojo.po.UserPO;
import com.examplemartin.jpademo.pojo.po.repository.purchase.PurInPO;
import com.examplemartin.jpademo.pojo.po.supplier.SupplierPO;
import java.io.Serializable;
import java.util.*;
import javax.persistence.*;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

/**
 * 采购订单实体
 */

@Data
@EqualsAndHashCode(callSuper = true)
@Entity(name = "t_pur")
public class PurPO extends BaseEntity implements Serializable {

  /*public static Integer PURPO_STATUS_SPARE = 0;
  public static Integer PURPO_STATUS_WAIT = 1;
  public static Integer PURPO_STATUS_RUNNING = 2;
  public static Integer PURPO_STATUS_FINISH = 3;
  public static Integer PURPO_STATUS_DISABLE = 4;

  public static String PURPO_STATUS_SPARE_NAME = "编制...";
  public static String PURPO_STATUS_WAIT_NAME = "等待...";
  public static String PURPO_STATUS_RUNNING_NAME = "编制...";
  public static String PURPO_STATUS_FINISH_NAME = "结束...";
  public static String PURPO_STATUS_DISABLE_NAME = "失效...";*/


  public static Integer PURPO_STATUS_SPARE = 0;
  public static Integer PURPO_STATUS_RUNNING = 1;
  public static Integer PURPO_STATUS_FINISH = 2;

  public static String PURPO_STATUS_SPARE_NAME = "编制...";
  public static String PURPO_STATUS_RUNNING_NAME = "执行...";
  public static String PURPO_STATUS_FINISH_NAME = "结束...";


  public static ArrayList<Integer> PURPO_STATUS_VALUE = new ArrayList<Integer>((Arrays.asList(PURPO_STATUS_SPARE,
          PURPO_STATUS_RUNNING,
          PURPO_STATUS_FINISH
  )));

  public static ArrayList<String> PURPO_STATUS_NAME= new ArrayList<String>((Arrays.asList(PURPO_STATUS_SPARE_NAME,
          PURPO_STATUS_RUNNING_NAME,
          PURPO_STATUS_FINISH_NAME
  )));




  /*public static ArrayList<String> PURPO_STATUS_NAME = new ArrayList<String>((Arrays.asList(PURPO_STATUS_SPARE_NAME ,
      PURPO_STATUS_WAIT_NAME ,
      PURPO_STATUS_RUNNING_NAME ,
      PURPO_STATUS_FINISH_NAME ,
      PURPO_STATUS_DISABLE_NAME )));

  public static ArrayList<Integer> PURPO_STATUS_VALUE = new ArrayList<Integer>((Arrays.asList(PURPO_STATUS_SPARE,
      PURPO_STATUS_WAIT,
      PURPO_STATUS_RUNNING,
      PURPO_STATUS_FINISH,
      PURPO_STATUS_DISABLE)));
*/


  // 订单好
  @EntityCheck(required = true, errRequired = "必须输入订单号")
  private String name;

  // 要货日期
  private Date need;

  // 订单状态
  private Integer status = PURPO_STATUS_SPARE;

  // 备注
  private String comment;

  // 对应采购员 one
  @ManyToOne
  @JoinColumn(nullable = false)
  @NotFound(action= NotFoundAction.IGNORE)
  private UserPO userPO;

  // 对应供应商 one
  @ManyToOne
  private SupplierPO supplierPO;


  // 对应采购入库单 list
  @OneToMany(mappedBy = "purPO")
  @JsonIgnore
  private List<PurInPO> purInPOList;

  // 对应采购订单明细 list
  @OneToMany(mappedBy = "purPO")
//  @JsonIgnore
  private List<PurDetailPO> purDetailPOList;


  @Override
  public String toString() {
    return "PurPO{" +
            "name='" + name + '\'' +
            ", need=" + need +
            ", status=" + status +
            ", comment='" + comment + '\'' +
            ", userPO=" + userPO +
            ", supplierPO=" + supplierPO +
            '}';
  }
}
